package com.chaos.framework.model.helper;

import com.chaos.framework.model.dto.page.PageList;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.model.dto.result.list.ListResult;
import com.chaos.framework.model.dto.result.page.PageResult;
import com.chaos.framework.model.exception.BusinessException;

import java.util.List;

public class ResultHelper {

    public static <T> T getDataResult(DataResult<T> dataResult) {
        if (dataResult.isSuccess()) {
            return dataResult.getData();
        }
        throw new BusinessException(dataResult.getCode(), dataResult.getMsg());
    }

    public static <T> List<T> getListResult(ListResult<T> listResult) {
        if (listResult.isSuccess()) {
            return listResult.getList();
        }
        throw new BusinessException(listResult.getCode(), listResult.getMsg());
    }

    public static <T> PageList<T> getPageResult(PageResult<T> pageResult) {
        if (pageResult.isSuccess()) {
            return pageResult.getPage();
        }
        throw new BusinessException(pageResult.getCode(), pageResult.getMsg());
    }

}